package runner.BF_VM;

import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.power.PowerHost;
import org.cloudbus.cloudsim.power.PowerVmAllocationPolicyAbstract;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class PowerVmAllocationPolicyBF extends PowerVmAllocationPolicyAbstract {


    public PowerVmAllocationPolicyBF(List<? extends Vm> vmList, List<? extends Host> list) {
        super(list);
    }

    @Override
    public List<Map<String, Object>> optimizeAllocation(List<? extends Vm> vmList) {
        return null;
    }


    @Override
    public PowerHost findHostForVm(Vm vm) {
        List<PowerHost> hostList = this.getHostList();
        Collections.sort(hostList, new Comparator<PowerHost>() {
            @Override
            public int compare(PowerHost o1, PowerHost o2) {
//                int a = (int) (o1.getTotalMips() - o1.getUtilizationOfCpuMips());
//                int b = (int) (o2.getTotalMips() - o2.getUtilizationOfCpuMips());
                return o2.getTotalMips() - o1.getTotalMips();
            }
        });
        for (PowerHost powerHost : hostList) {
            if (powerHost.isSuitableForVm(vm)) {
                return powerHost;
            }

        }

        return super.findHostForVm(vm);
    }
}
